<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台--文章管理</title>
    <link rel="stylesheet" type="text/css" href="<?php echo isset($skin)?$skin:"";?>images/style.css" />
    <base target="_self"/>

    <script src='<?php echo isset($skin)?$skin:"";?>js/jquery.min.js'></script>
    <script type="text/javascript" src="<?php echo isset($skin)?$skin:"";?>js/jquery.form.min.js"></script>
    <script type="text/javascript" src="<?php echo isset($skin)?$skin:"";?>js/dist/dialog-min.js"></script>
    <script src="<?php echo isset($skin)?$skin:"";?>js/admin.js"></script>
    <script type="text/javascript">
        <!--
        $(document).ready(function () {
            $('.new_table tbody tr:even').addClass('h'); //奇偶变色，添加样式
        });
        //-->
    </script>

</head>
<body>
<div class="hh6"></div>
<script charset="utf-8" src="../kedit/kindeditor-min.js"></script>
<script type="text/javascript">
    $(function(){
        $(".nav a").click(function(){
            $(this).addClass("current").siblings().removeClass("current");
            $(".new_table").eq($(this).index()).removeClass("hidden").siblings(".new_table").addClass("hidden");
        });
        $("#set").click(function(){
            $(".hidden").show("slow");
        });
    });
</script>
<script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>/js/validate.js"></script>
<script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>js/artTemplate.js"></script><script type="text/javascript" charset="UTF-8" src="/runtime/_systemjs/artTemplate/artTemplate-plugin.js"></script>

<div class="nav">
    <div class="navc">
        <a class="current" href="javascript:void(0)">基本信息</a>
        <a href="javascript:void(0)">栏目内容</a>
        <a href="javascript:void(0)">模板管理</a>
    </div>
</div>
<form method="Post" action="?c=<?php echo isset($classname)?$classname:"";?>" name="k_form">
    <table class="new_table" width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
        <thead>
        </thead>
        <tbody>
        <tr>
            <td width="13%" height="30" align="right">扩展名称：</td>
            <td width="87%"><input class="normal" name="model_name" id="model_name" type="text" pattern="required" alt="模型名称不能为空！" value="<?php echo isset($name)?$name:"";?>"  /> <label>* 模型名称（必填）</label>
            </td>
        </tr>
        <tr>
            <td align="right">添加扩展属性：</td>
            <td><button class="btn" onclick="addAttr()" type="button"><span class="add">添加扩展属性</span></button></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <table width="90%" class='border_table'>
                    <thead>
                    <tr>
                        <th>属性名</th>
                        <th>操作样式</th>
                        <th>选择项数据【每项数据之间用逗号','做分割】</th>
                        <th>是否作为商品的筛选项</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="attr_list"></tbody>

                    <!--属性列表-->
                    <script type='text/html' id='attrListTemplate'>
                        <%for(var item in templateData){%>
                        <%include('attrTrTemplate',{'item':templateData[item]})%>
                        <%}%>
                    </script>

                    <!--属性单行-->
                    <script type='text/html' id='attrTrTemplate'>
                        <tr class='td_c'>
                            <td>
                                <input class="input200" name='attr[id][]' type='hidden' value="<%=item['id']%>" />
                                <input class="input200" name='attr[name][]' class='small' type='text' pattern='required' value="<%=item['name']%>" />
                            </td>
                            <td>
                                <select class="middle" name='attr[show_type][]'>
                                    <option value='1' <%if(item['type']=='1'){%>selected<%}%>>单选框</option>
                                    <option value='2' <%if(item['type']=='2'){%>selected<%}%>>复选框</option>
                                    <option value='3' <%if(item['type']=='3'){%>selected<%}%>>下拉框</option>
                                    <option value='4' <%if(item['type']=='4'){%>selected<%}%>>输入框</option>
                                </select>
                            </td>
                            <td>
                                <input class="input200" class='normal' name='attr[value][]' type='text' value="<%=item['value']%>" />
                            </td>
                            <td>
                                <input type='checkbox' <%if(item['search']== '1'){%>checked<%}%> onclick="selectCheck(this)" />
                                <input type='hidden' name='attr[is_search][]' value="<%=item['search']?item['search']:0%>" />
                            </td>
                            <td>
                                <span class="del" alt="删除" onclick="delAttr(this)" />
                            </td>
                        </tr>
                    </script>
                </table>
            </td>
        </tr>


        <tr>
            <td height="35" colspan="2" align="center" ><input name="into_wz" id="submit" class="button" type="submit" value="提交" />
                &nbsp;<input name="" type="reset" class="button" value="重置" />
                <input name="id" type="hidden" value="<?php echo isset($id)?$id:"";?>" />
                <input name="a" type="hidden" value="update" />
            </td>
        </tr>
</tbody>
        </table>

</form>
<script type='text/javascript'>
    $(function(){
        //初始化属性
        <?php if($attr){?>
            var attrListHtml = template.render('attrListTemplate',{'templateData':<?php echo isset($attr)?$attr:"";?>});
            $('#attr_list').html(attrListHtml);
        <?php }?>
        //初始化规格
            <?php if($spec){?>
            var specListHtml = template.render('specListTemplate',{'templateData':<?php echo isset($spec)?$spec:"";?>});
            $('#spec_list').html(specListHtml);<?php }?>
        });

    //添加模型规格
    function addSpec()
    {
        art.dialog.open('/index.php?controller=goods&action=select_spec', {
            title: '选择规格',
            okVal:'保存',
            ok:function(iframeWin, topWin){
                var specChecked = $(iframeWin.document).find('[name="spec"]:checked');
                if(specChecked.length == 1)
                {
                    var specJson = $.parseJSON(specChecked.val());
                    var specTrHtml = template.render('specTrTemplate',{'item':specJson});
                    $('#spec_list').append(specTrHtml);
                }
            }
        });
    }

    //添加一个模型属性
    function addAttr()
    {
        var attrTrHtml = template.render('attrTrTemplate',{'item':[]});
        $('#attr_list').append(attrTrHtml);
    }

    //删除模型属性
    function delAttr(curr_attr)
    {
        $(curr_attr).parent().parent().remove();
    }

    //选择当前Tab
    function selectTab(curr_tab)
    {
        $("table[name='table']").hide();
        $("#tab-"+curr_tab).show();
        $("ul[name=menu1] > li").removeClass('selected');
        $('#li_'+curr_tab).addClass('selected');
    }

    //设置选择复选框的值
    function selectCheck(_self)
    {
        var checkValue = $(_self).siblings('[name="attr[is_search][]"]')[0];

        if($(_self).attr("checked"))
        {
            checkValue.value = 1;
        }
        else
        {
            checkValue.value = 0;
        }
    }

    //项上升
    function positionUp(_self,container)
    {
        var childrenIndex = container.children().index(_self);
        if(childrenIndex == 0)
        {
            return;
        }
        _self.insertBefore(container.children().get(childrenIndex-1));
    }

    //项下降
    function positionDown(_self,container)
    {
        var childrenIndex = container.children().index(_self);
        if(childrenIndex == container.children().length - 1)
        {
            return;
        }
        _self.insertAfter(container.children().get(childrenIndex+1));
    }
</script>

</body>
</html>